﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Net.Mail;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Net.Mime;

namespace NPSoft.Ferrero.Framework.Utility.Test
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestMethod1()
        {
            MailHelper mail = new MailHelper();
            mail.Account = "newspageinterface@ferrero.com.cn";
            mail.Password = "hello2836";
            MailMessage msg = new MailMessage();
            msg.From = new MailAddress(mail.Account, "FerreroCloud");
            msg.Body = "测试邮件！";

            DataTable dt = new DataTable();
            dt.Columns.Add("Col1");
            DataRow dr = dt.NewRow();
            dr[0] = "Test";
            dt.Rows.Add(dr);

            byte[] bys = mail.GetAttachStream(dt);
            if (bys != null && bys.Length > 0)
            {
                MemoryStream ms = new MemoryStream();
                Attachment at = new Attachment(ms, "ErrorMsg.xlsx", MediaTypeNames.Text.Plain);
                msg.Attachments.Add(at);
            }

            List<MailAddress> address = new List<MailAddress>();
            address.Add(new MailAddress("yongbo.li@avanade.com"));
            msg.Subject = "测试邮件";
            mail.SendBySMTP(address,address, msg);

            msg.Attachments.Dispose();
        }

        [TestMethod]
        public void TestMethod2()
        {
            string subject = "{0} Error Message_" + DateTime.Now.ToString("yyyyMMddHHmmss");
            bool s = NPValidator.IsEmail("yongbo.li@avanade.com");
            string pwd = EncryptHelper.DesEncrypt("NewsPage");
        }
    }
}
